package game;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

//52张牌
public class CardDemo {
    private String[] suits = {"♥","♠","♦","♣"};

    //买牌(52)
    public List<Card> buyCard() {
        List<Card> cardList = new ArrayList<>();
        for (int i = 1; i <= 14; i++) {
            for (int j = 0; j < 4; j++) {
                cardList.add(new Card(suits[j],i));
            }
        }
        return cardList;
    }

    //洗牌
    private void swap(int a, int b, List<Card> cardList) {
        Card tmp = cardList.get(a);
        cardList.set(a,cardList.get(b));
        cardList.set(b,tmp);
    }
    public void washCard(List<Card> cardList) {
        Random random = new Random();
        for (int i = 51; i > 0; i--) {
            int tmp = random.nextInt(i);
            swap(i,tmp,cardList);
        }
    }

    //发牌
    public List<List<Card>> pushCard(List<Card> cardList) {
        //三个人。每一个都是一个数组
        List<Card> hand0 = new ArrayList<>();
        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();

        //用一个类似二维数组来存储这三个人多的所有牌
        List<List<Card>> hands = new ArrayList<>();
        hands.add(hand0);
        hands.add(hand1);
        hands.add(hand2);
        for(int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                //每次从最上面摸一张牌就相当于将最上面的牌给去除掉
                Card tmp = cardList.remove(0);
                hands.get(j).add(tmp);
            }
        }
        return hands;
    }
}
